﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Geekees.Common.Controls;
using Geekees.Common.Utilities.Xml;

public partial class WebControls_TreeViewControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GenerateTree();
        }
    }

    private void GenerateTree()
    {
        string v_str_donviID = Request.QueryString["donviId"];
        int v_int_donviID = 0;
        int.TryParse(v_str_donviID, out v_int_donviID);

        string v_str_nganhID = Request.QueryString["nganhId"];
        int v_int_nganhID = 0;
        int.TryParse(v_str_nganhID, out v_int_nganhID);

        string v_str_monhocID = Request.QueryString["monhocId"];
        int v_int_monhocID = 0;
        int.TryParse(v_str_monhocID, out v_int_monhocID);

        ASTreeViewLinkNode nd = new ASTreeViewLinkNode("Picasa", "Picasa", "http://picasaweb.google.com", "frm");
        nd.NodeText = "Chưa có ngành nào.";
        nd.EnableChildren = false;
        nd.EnableEditContextMenu = false;

       // ASTreeViewNode note;
         ASTreeViewLinkNode note;
        ASTreeViewLinkNode nl;
        ASTreeViewLinkNode nMonHoc;
        foreach (DM_DON_VI_SU_DUNG dv in Services.GetDsDM_DON_VI_SU_DUNG())
        {
            if (v_int_donviID == (int)dv.ID)
            {
                note = new ASTreeViewLinkNode("<strong><FONT color = red >" + dv.TEN_DON_VI + "</FONT></strong>", dv.ID.ToString(), String.Format("~/F530.aspx?donviId={0}", dv.ID), "");
            }
            else {
                note = new ASTreeViewLinkNode(dv.TEN_DON_VI, dv.ID.ToString(), String.Format("~/F530.aspx?donviId={0}", dv.ID), "");
            }
            List<DM_NGANH_DAO_TAO> lshNghanh = Services.GetDsDM_NGANH_DAO_TAOByDonViId((int)dv.ID);
            if (lshNghanh.Count > 0)
            {
                foreach (DM_NGANH_DAO_TAO ng in lshNghanh)
                {
                    if ((v_int_donviID == (int)dv.ID) && (v_int_nganhID == (int)ng.ID))
                    {
                        nl = new ASTreeViewLinkNode("<strong><FONT color = red >" + ng.TEN_NGANH + "</FONT></strong>", ng.ID.ToString(), String.Format("~/F510.aspx?donviId={0}&nganhId={1}", dv.ID, ng.ID), "");
                    }
                    else {
                        nl = new ASTreeViewLinkNode(ng.TEN_NGANH, ng.ID.ToString(), String.Format("~/F510.aspx?donviId={0}&nganhId={1}", dv.ID, ng.ID), "");
                    }

                    List<DM_MON_HOC> lshMonHoc = Services.GetDsDM_MON_HOC((int)dv.ID, (int)ng.ID);
                    if (lshMonHoc.Count > 0)
                    {
                        foreach (DM_MON_HOC MH in lshMonHoc)
                        {
                            if ((v_int_donviID == (int)dv.ID) && (v_int_nganhID == (int)ng.ID) && (v_int_monhocID == (int)MH.ID))
                            {
                                nMonHoc = new ASTreeViewLinkNode("<strong><FONT color = red >" + MH.TEN_TIENG_VIET + "</FONT></strong>", MH.ID.ToString(), String.Format("~/F520.aspx?donviId={0}&nganhId={1}&monhocId={2}", dv.ID, ng.ID, MH.ID), "");
                            }
                            else
                            {
                                nMonHoc = new ASTreeViewLinkNode( MH.TEN_TIENG_VIET , MH.ID.ToString(), String.Format("~/F520.aspx?donviId={0}&nganhId={1}&monhocId={2}", dv.ID, ng.ID, MH.ID), "");
                            }
                            nl.AppendChild(nMonHoc);
                        }
                    }
                    note.AppendChild(nl);
                }
            }
            else
            {
                note.AppendChild(nd);
            }
            astvMyTree.RootNode.AppendChild(note);
        }

        astvMyTree.ContextMenu.Visible = false;
        astvMyTree.EnableCheckbox = false;
    }
}